﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using ParkingLot.Entitys.DbSessionEntitys;
using ParkingLot.Utility.LogHelps;
using ParkingLot.Utility.SerializeHelp;

namespace ParkingLot.Utility.Factory
{
    /// <summary>
    /// 读取数据库文件
    /// </summary>
    public class DBEntityFactory
    {
        /// <summary>
        /// 文件名称
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static DbSessionEntity GetDbSessionEntity(string fileName)
        {
            try
            {
                XDocument xDocument = XDocument.Load($"{AppDomain.CurrentDomain.BaseDirectory}DateBaseCommandText//{fileName}");
                string value2 = xDocument.ToString();
                DbSessionEntity dbSessionEntity = XmlHelp.DeXMLSerialize<DbSessionEntity>(value2);
                return dbSessionEntity;
            }
            catch (Exception exception)
            {
                LogHelp.AddLog(new LogEncity($"读取文件：{fileName}出错,请检查文件是否存在", exception));
                return null;
            }

        }
    }
}
